<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <meta name="csrf_token" id="token" content="{{ csrf_token() }}">
    @include('public.h5_head')
    <title>求货</title>
    <script src="{{ env('CDN_DOMAIN_NAME') }}/js/commonjs/rem.js"></script>
    <link href="{{env('CDN_DOMAIN_NAME')}}/css/font-awesome.min.css" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="{{ env('CDN_DOMAIN_NAME') }}/css/commoncss/common.css"/>
    <link rel="stylesheet" type="text/css" href="{{ env('CDN_DOMAIN_NAME') }}/css/buySup.css?v=1.0.3"/>
</head>
<script src="{{ env('CDN_DOMAIN_NAME') }}/js/app.js"></script>
<script src="{{ env('CDN_DOMAIN_NAME') }}/js/commonjs/common.js"></script>
<script src="{{ env('CDN_DOMAIN_NAME') }}/store/js/main.js"></script>
<bodys>
    <div id="box_take">
        <div class="wrap">
            <div class="wrap_div">
                <ol class="take_ol">
                    <li class="take_lis">门店信息</li>
                    <li class="take_address">
                        <span class="lisp">地址</span>
                        <p class="address_p">{{$user_area->user_area.$user_area->area_detail}}</p>
                    </li>
                    <li class="take_lis">库存详情</li>
                    <li class="take_lis"><span class="lisp">款号</span><p class="p1"><?php echo $_GET['girard'];?></p></li>
                    <li class="take_liscolor">
                        <span class="lisp">颜色</span>
                        <p class="Colors">
                            @foreach ($new_data['color'] as $k)
                                <a href="javascript:;" class="colorA">{{$k}}</a>
                            @endforeach
                        </p>
                    </li>
                </ol>
                @foreach ($new_data['color'] as $k )
                    <ul class="take_ul">
                        @foreach ($new_data['size_num'] as $kk => $vv)
                            <li class="take_li">
                                <div class="gou noclick" abc="{{ $vv['size'] }}"><i class="fa fa-circle-thin"></i></div>
                                <span>{{$vv['size']}}码</span>
                                <div class="spinner">
                                    <a class="decrease" style="pointer-events:none;background:#f1f1f1;">-</a>
                                    <input type="tel" disabled class="spinnerExample nums" maxlength="2" min="0" step="1" value="0">
                                    <a class="increase">+</a>
                                </div>
                            </li>
                        @endforeach
                    </ul>
                @endforeach
            </div>
        </div>
        <div class="btn_take">
            <a href="javascript:;" class="sure_take">确定</a>
        </div>
        <div class="provider">
            <div class="pro_top">
                <div class="shut"><img src="/img/zuojiantou.png"></div>
                <span>汇总</span>
                <div class="shut">×</div>
            </div>
            <div class="count_pro">
                <div class="pro_center">
                    <div class="cen_Div">
                        <span class="pro_tit">款号</span>
                        <p class="pro_p"></p>
                    </div>

                </div>
                <div class="mu-2"><img src="/img/scrolls.png"></div>
            </div>
            <div class="pro_bottom">
                <button class="pro_a">再次确认</button>
            </div>
        </div>
        <div class="tip_hide" style="display: none;"></div>
        <div class="mask" style="display:none;"></div>
    </div>
</bodys>
<script>
    is_weixn('.btn_take');
    $(document).ready(function() {
        if($.getUrlParam('from') == 'transfer'){
            $('.sure_take').hide();
            $('.increase').css({'pointer-events':'none','background':'#f1f1f1'});
            $.ajax({
                url:'/customer/get-publish-details',
                type:'post',
                data:{
                    type:1,
                    girard:$.getUrlParam('girard')
                },
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                },
                dataType:'json',
                success:function(res){
                    var data = res.info.size_nums;
                    var data1 = {};
                    data1 = data;
                    for(var x = 0;x<$('.colorA').length;x++){
                        for(var tmp in data){
                            if($('.colorA').eq(x).text() == tmp){
                                $('.colorA').eq(0).addClass("on");
                                $(".take_ul").hide();
                                $(".take_ul").eq(0).show();
                                $.each(data1[tmp],function(idx,obj){
                                    for(var i =0;i<$('.take_ul').eq(x).children('.take_li').length;i++){
                                        if($('.take_ul').eq(x).children('.take_li').eq(i).children('.gou').attr('abc') == obj.size){
                                            $('.take_ul').eq(x).children('.take_li').eq(i).children('.gou').attr('class','gou choose');
                                            $('.take_ul').eq(x).children('.take_li').eq(i).children('.gou').children('i').attr('class','fa fa-check-circle');
                                            $('.take_ul').eq(x).children('.take_li').eq(i).children('.spinner').children('.nums').val(obj.num);
                                        }
                                    }
                                });
                            }
                        }
                    };
                    $('.noclick').removeClass('gou');
                }
            });
        };
    })
    /*选择颜色*/
    $(document).on("click",".colorA",function(){
        $(this).addClass("on");
        $(this).siblings().removeClass("on");
        var index=$(this).index();
        $(".take_ul").hide();
        $(".take_ul").eq(index).show();
    });
    /*码数选择*/
    $(document).on("click",".gou",function(){
        if($(this).children(".fa").hasClass("fa-check-circle")){
            $(this).removeClass("choose");
            $(this).children(".fa").remove();
            $(this).prepend("<i class='fa fa-circle-thin'></i>");
        }else{
            if($(this).siblings(".spinner").children(".nums").val()=='0'){
                $(this).siblings(".spinner").children(".nums").val("1");
                $(this).siblings(".spinner").children(".decrease").css({'background':'#fff','pointer-events':'auto'});
            }
            $(this).addClass("choose");
            $(this).children(".fa").remove();
            $(this).prepend("<i class='fa fa-check-circle'></i>");
        }
    });
    /*二次选择颜色*/
    $(document).on("click",".pro_Ti",function(){
        if($(this).children(".fa").hasClass("fa-check-circle")){
            $(this).parent(".cen_div").removeClass("elect");
            $(this).children(".fa").remove();
            $(this).prepend("<i class='fa fa-circle-thin'></i>");
        }else{
            $(this).parent(".cen_div").addClass("elect");
            $(this).children(".fa").remove();
            $(this).prepend("<i class='fa fa-check-circle'></i>");
        }
    });
    /*确定按钮*/
    $(".sure_take").click(function(){
        if($(".choose").length==0){
            $(".tip_hide").text("至少选择一个尺码数量");
            $(".tip_hide").show(0).delay(1000).hide(0);
        }else{
            $(".pro_p").text('');
            $(".cen_div").remove();
            $(".pro_p").text($(".p1").text());
            for(var j=0;j<$(".take_ul").length;j++){
                var res1='<span class="pro_Ti"><i class="fa fa-check-circle"></i><b>'+$(".colorA").eq(j).text()+'</b></span>'
                var s1=$(".take_ul").eq(j).children(".take_li").children(".choose");
                var res2='';
                for(var k=0;k<s1.length;k++){
                    res2=res2+'<div class="proDiv">' +
                        '<span>'+s1.eq(k).siblings("span").text()+'</span>' +
                        '<div class="spinner">' +
                        '<a class="decrease">-</a>' +
                        '<input type="tel" disabled class="spinnerExample" maxlength="2" min="0" step="1" value="'+s1.eq(k).siblings(".spinner").children(".spinnerExample").val()+'">' +
                        '<a class="increase">+</a>' +
                        '</div>' +
                        '</div>';
                }
                if(res2.length<=0){

                }else{
                    $(".pro_center").append('<div class="cen_div elect">'+res1+''+res2+'</div>');
                }
            }
            $(".mask").show();
            $(".provider").stop().slideDown(500);
            if(Number( $(".pro_center").height() )-Number( $(".count_pro").height() )>0){
                setTimeout(function(){
                    $(".mu-2").show();
                },600);
                setTimeout(function(){
                    $(".mu-2").hide();
                },5000);
            }else{
                $(".mu-2").hide();
            }
        }
    });
    /*点关闭*/
    $(".shut").click(function(){
        $(".mu-2").hide();
        $(".mask").hide();
        $(".provider").stop().slideUp(500);
    });
    //点击数量加减
    $(document).on("click",".increase",function(){//加
        var value=$(this).parent(".spinner").children(".spinnerExample").val();
        var num_add=parseInt(value)+1;
            if(num_add>=1){
                $(this).parent(".spinner").siblings(".gou").addClass("choose");
                $(this).parent(".spinner").siblings(".gou").children(".fa").remove();
                $(this).parent(".spinner").siblings(".gou").prepend("<i class='fa fa-check-circle'></i>");
            }
            $(this).parent(".spinner").children(".decrease").css({'background':'#fff','pointer-events':'auto'});
            $(this).parent(".spinner").children(".spinnerExample").val(num_add);
    });
    $(document).on("click",".decrease",function(){//减
        var value =$(this).parent(".spinner").children(".spinnerExample").val();
        var num_dec = parseInt(value)-1;
        if(num_dec==0){
            $(this).parent(".spinner").siblings(".gou").removeClass("choose");
            $(this).parent(".spinner").siblings(".gou").children(".fa").remove();
            $(this).parent(".spinner").siblings(".gou").prepend("<i class='fa fa-circle-thin'></i>");
            $(this).parent(".spinner").children(".spinnerExample").val(0);
            $(this).css({'background':'#f1f1f1','pointer-events':'none'});
            $(this).parent(".spinner").children(".increase").css({'background':'#fff','pointer-events':'auto'});
        }
        if(num_dec>0){
            $(this).parent(".spinner").children(".spinnerExample").val(num_dec);
            $(this).parent(".spinner").children(".increase").css({'background':'#fff','pointer-events':'auto'});
        }
    });
    /*提交*/
    $('.pro_a').click(function () {
        var girard=$(".pro_p").text();
        var colors='';
        var sizes='';
        var nums='';
        for(var n=0;n<$(".elect").length;n++){
            for(var z=0;z<$(".elect").eq(n).children(".proDiv").length;z++){
                colors=colors+$(".elect").eq(n).children(".pro_Ti").children("b").text()+',';
                var s5=$(".elect").eq(n).children(".proDiv").eq(z).children("span").text();
                var arr2=s5.split('码');
                sizes=sizes+arr2[0]+',';
                nums=nums+$(".elect").eq(n).children(".proDiv").eq(z).children(".spinner").children(".spinnerExample").val()+',';
            }
        }
        var color=colors.substr(0, colors.length - 1);
        var size=sizes.substr(0, sizes.length - 1);
        var num=nums.substr(0, nums.length - 1);
        $.ajax({
            url:'/customer/person-seeking-goods',
            type:'post',
            data:{
                girard: girard,
                color:color,
                size:size,
                num:num,
                type:1
            },
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
            },
            dataType:'json',
            success:function(data){
                if(data.success){
                    //console.log(data);
                    $(".tip_hide").text("添加成功");
                    $(".tip_hide").show(0).delay(800).hide(0);
                    setTimeout(function(){
                        window.location.href='/customer/product-lists';
                    },800)
                }else{
                    $(".tip_hide").text("添加失败");
                    $(".tip_hide").show(0).delay(1000).hide(0);
                }
            }
        })
    });
</script>
</html>
